package com.example.luozizhao.eprxdemo.commom;

import android.app.Activity;

import java.util.HashSet;

/**
 * Created by luozizhao on 2018/5/16.
 */

public class ActivityControl {

    private static ActivityControl mActControl;
    private  HashSet<Activity> mActivitys;


    public static ActivityControl getInstance(){
        if (mActControl==null) {
            synchronized (ActivityControl.class){
                if (mActControl==null) {
                    mActControl = new ActivityControl();
                }
            }
        }
        return mActControl;
    }


    public void addActivity(Activity activity){
        if (mActivitys==null) {
            mActivitys = new HashSet<Activity>();
        }
        mActivitys.add(activity);
    }



    public void removeActivity(Activity activity){
        if (mActivitys!=null) {
            if (mActivitys.contains(activity)) {
                mActivitys.remove(activity);
            }
        }
    }


    /**
     * 一键退出app
     */
     public void exitApp(){
         if (mActivitys!=null) {
             synchronized(mActivitys){
                 for (Activity act:mActivitys) {
                     mActivitys.remove(act);
                 }
             }
         }
         android.os.Process.killProcess(android.os.Process.myPid());
//         System.exit(0);

     }

}
